#pragma once
#include "kernel\femeshfunction.h"

class LinearCombinationFunction :
	public feMeshFunction
{
	feMeshFunction *F1;
	feMeshFunction *F2;
	double			Coeff1;
	double			Coeff2;


public:
	LinearCombinationFunction() { F1 = F2 = 0; Coeff1 = Coeff2 = 0; }
	void SetF1F2(feMeshFunction *iF1, feMeshFunction *iF2) { F1 = iF1; F2 = iF2; }
	void SetCoeff1(double iCoeff1) { Coeff1 = iCoeff1; }
	void SetCoeff2(double iCoeff2) { Coeff2 = iCoeff2; }
	virtual void	  AddLayer(double iTime, feVector *iLayer)	{ F1->AddLayer(iTime, iLayer); F2->AddLayer(iTime, iLayer); } 
	virtual feMesh*   GetMesh()									{ return F1->GetMesh(); }
	virtual void	  ReserveLayers(int iCount)					{ F1->ReserveLayers(iCount); F2->ReserveLayers(iCount); }
	virtual double	  GetTime(int iIndex)						{ return F1->GetTime(iIndex); }
	virtual int		  LayersCount()								{ return F1->LayersCount(); }
	virtual double	  GetU(fePoint *iP, double iTime, int *iLookUp = 0) { return Coeff1*F1->GetU(iP, iTime, iLookUp) + Coeff2*F2->GetU(iP, iTime, iLookUp); }
	virtual double	  GetU(int iNode, double iTime)						{ return Coeff1*F1->GetU(iNode, iTime) + Coeff2*F2->GetU(iNode, iTime); }
	virtual double	  GetU(fePoint *iP, int iLayerNum, int *iLookUp = 0){ return Coeff1*F1->GetU(iP, iLayerNum, iLookUp) + Coeff2*F2->GetU(iP, iLayerNum, iLookUp); }
	virtual double	  GetU(int iNode, int iLayerNum)					{ return Coeff1*F1->GetU(iNode, iLayerNum) + Coeff2*F2->GetU(iNode, iLayerNum); }
	virtual double	  GetDuDt(fePoint *iP, double iTime)				{ return Coeff1*F1->GetDuDt(iP, iTime) + Coeff2*F2->GetDuDt(iP, iTime); }
	virtual double	  GetDuDt(fePoint *iP, int iLayerNum)				{ return Coeff1*F1->GetDuDt(iP, iLayerNum) + Coeff2*F2->GetDuDt(iP, iLayerNum); }
	virtual double	  GetDuDt(int iNode, double iTime)					{ return Coeff1*F1->GetDuDt(iNode, iTime) + Coeff2*F2->GetDuDt(iNode, iTime); }
	virtual double	  GetDuDt(int iNode, int iLayerNum)					{ return Coeff1*F1->GetDuDt(iNode, iLayerNum) + Coeff2*F2->GetDuDt(iNode, iLayerNum); }
	virtual feVector* GetLayer(int iIndex)								{ return F1->GetLayer(iIndex); }
	virtual bool	  SaveToFile(char *iFileName, char *iMeshFileName)	{ return false; }
	virtual double	  GetDuDx(fePoint *iP, double iTime)				{ return Coeff1*F1->GetDuDx(iP, iTime) + Coeff2*F2->GetDuDx(iP, iTime); }
	virtual double	  GetDuDx(fePoint *iP, int iLayerNum)				{ return Coeff1*F1->GetDuDx(iP, iLayerNum) + Coeff2*F2->GetDuDx(iP, iLayerNum); }
	virtual double	  GetDuDx(int iNode, double iTime)					{ return Coeff1*F1->GetDuDx(iNode, iTime) + Coeff2*F2->GetDuDx(iNode, iTime); }
	virtual double	  GetDuDx(int iNode, int iLayerNum)					{ return Coeff1*F1->GetDuDx(iNode, iLayerNum) + Coeff2*F2->GetDuDx(iNode, iLayerNum); }
	virtual bool	  LoadFromFile(char *iFileName) { return false; }
	virtual void	  Clear() { F1->Clear(); F2->Clear(); }
};
